package com.ms.yk;

import android.content.Intent;

import com.ms.yk.service.SmsObserverService;

public class MainActivity extends BaseActivity {

    @Override
    public int getContentViewId() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
//        OkHttpClient client = new OkHttpClient();//创建OkHttpClient对象。
//        FormBody.Builder formBody = new FormBody.Builder();//创建表单请求体
//        formBody.add("username", "123345");
//        formBody.add("message", "测试");
//        final Request request = new Request.Builder()//创建Request 对象。
//                .url("http://106.14.210.82/api/post_message.php")
//                .post(formBody.build())//传递请求体
//                .build();
//        client.newCall(request).enqueue(new Callback() {
//
//            @Override
//            public void onFailure(Call call, IOException e) {
//                System.out.println(e.toString());
//            }
//
//            @Override
//            public void onResponse(Call call, Response response) {
//                if (response != null && response.isSuccessful()) {//回调的方法执行在子线程。
//                    try {
//                        JSONObject result = new JSONObject(response.body().string());
//                        System.out.println(result.toString(2));
//                        //{"code":10001,"data":null,"msg":false}
//                        int code = result.optInt("code");
//                        String msg = result.optString("msg");
//                        System.out.println(result.toString());
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                }
//            }
//        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        onOpenService();
    }

    public void onOpenService() {
        Intent intent = new Intent(MainActivity.this, SmsObserverService.class);
        startService(intent);
    }
}